package com.ruoyi.manage.report.mapper;
import com.ruoyi.manage.report.domain.EnterpriseLoanInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
/**
 * 企业贷款信息Mapper接口
 *
 * @author ruoyi
 * @date 2025-10-02
 */
public interface EnterpriseLoanInfoMapper extends BaseMapper<EnterpriseLoanInfo>{

    @Select("SELECT " +
            "   1306 AS platform_id, " +
            "   m.credit_code, " +
            "   m.enterprise_name, " +
            "   IF(i.real_name_flag = 1, '是', '否') AS real_name_certification, " +
            "   l.name AS operator_name, " +
            "   '法人' AS operator_identity, " +
            "   l.id_card AS operator_id_card_no, " +
            "   i.registered_capital, " +
            "   l.term_type AS operating_time_limit_type, " +
            "   '是' AS is_private_enterprise, " +
            "   '' AS down_loan, " +
            "   NOW() AS load_date, " +
            "   b.org_name AS loan_org_name, " +
            "   b.credit_code AS loan_org_unisc_id, " +
            "   b.org_code AS loan_org_code, " +
            "   o.loan_amount, " +
            "   o.interest_rate_limit_upper AS loan_rate, " +
            "   o.main_guarantee_way AS guarantee_mode, " +
            "   o.loan_period_limit_upper AS maturity, " +
            "   o.repayment_way AS repayment_ways, " +
            "   o.order_state AS status, " +
            "   UUID_SHORT() AS external_system_id " +
            "FROM " +
            "   oc_business_financing_order o " +
            "   LEFT JOIN biz_organization b ON b.org_path = o.org_path " +
            "   LEFT JOIN oc_financing_match m ON m.mach_id = o.mach_id " +
            "   LEFT JOIN ec_enterprise_information i ON i.credit_code = m.credit_code " +
            "   LEFT JOIN ec_enterprise_legal l ON l.enterprise_id = i.id " +
            "WHERE " +
            "   o.create_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')")
    List<EnterpriseLoanInfo> selectBusinessFinancingList();
}